home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nejlepší hry
/
Nejlepsi hry.iso
/
hry
/
sea of chaos
/
sea_install.msi
/
_15C39AAA7726369D39812BD40F01CF6A
/
_A00F65CAE1224EE99A35E0CAD0F28D36
< prev
next >
Wrap
Text File
|
2005-03-04
|
1KB
|
60 lines
//simple per-pixel phong shading
//1 directional light applied
//Luke Lenhart
//(C)2004-2005 Digipen Institute of Technology
//directional light (assumed to be the sun)
float4 lgtDirection;
float4 lgtDiffuse;
float4 lgtAmbient;
//position of the eye
float4 posEye;
//base texture
sampler2D sampTex;
//specular hardness and amount of specular to use
float specHard;
float specAmount;
//shader input
struct PS_INPUT
{
float3 Normal : TEXCOORD2;
float3 Pos : TEXCOORD1;
float2 Tex0 : TEXCOORD0;
float4 Clr : COLOR;
};
float4 PShader(PS_INPUT In) : COLOR
{
In.Normal.xyz=normalize(In.Normal.xyz);
//calc diffuse
float3 diff=lgtDiffuse.xyz*dot(lgtDirection.xyz,In.Normal.xyz)*tex2D(sampTex,In.Tex0);
//calc specular
//float3 dirEye=normalize(posEye.xyz-In.Pos.xyz);
//float3 spec=saturate(sin(3.1415*dot(reflect(-lgtDirection.xyz,In.Normal.xyz),dirEye)));
//spec=pow(spec,15);
float3 dirEye=normalize(posEye.xyz-In.Pos.xyz);
float3 rNorm=reflect(-lgtDirection.xyz,In.Normal.xyz);
float3 spec=saturate(dot(rNorm,dirEye));
//spec=cos((1-spec)*3.14159f*0.5f);
spec=pow(sin(spec*3.14159f*0.5f),specHard);
//mix
float4 clr;
clr.xyz=lgtAmbient.xyz + diff + specAmount*spec;
clr.a=1;
clr*=In.Clr;
//return final color
return clr;
}